<template>
  <a-modal title="导出采购员数据" style="top: 100px;" :visible="isShow" width="600px" @ok="handleOk" @cancel="handleCancel"
    okText="确认导出">
    <IForm :formFrame="frame" class="form-container" :formData.sync="form"></IForm>
  </a-modal>
</template>
<script>
  import {
    mapGetters
  } from 'vuex'
  import {
    ACCESS_TOKEN
  } from '@/store/mutation-types'
  import IForm from "@/components/IForm"

  export default {
    components: {
      IForm
    },
    props: {
      isShow: {
        type: Boolean
      }
    },
    computed: {
      ...mapGetters(['baseUrl']),
      frame() {
        return [
          {
            title: '采购时间(始)',
            key: 'created_start_at',
            type: 'date',
            showTime: false,
            required: true,
          },
          {
            title: '采购时间(结束)',
            key: 'created_end_at',
            type: 'date',
            showTime: false,
            required: true,
          },
          {
            title: '采购员',
            key: 'admin_id',
            type: 'select',
            span: 12,
            options: this.admin_list
          },
          {
            title: '导出类型',
            key: 'type',
            type: 'radio',
            default: 2,
            required: true,
            span: 24,
            options: [{
                title: '粗略',
                value: 1
              },
              {
                title: '详细',
                value: 2
              }
            ],
            tips: ''
          },
        ]
      }
    },
    data() {
      return {
        form: {
          abc: "abc"
        },
        admin_list: [],
        admin_id: undefined,
      }
    },
    watch: {
      form: {
        deep: true
      }
    },
    mounted () {
      this.$http.get('/storage_admin_list').then(res => {
        this.admin_list = res.data.list
        this.admin_list = this.admin_list.map(item => {
          return {
            title: item.name,
            value: item.admin_id
          }
        })
      })
    },
    methods: {
      handleChange({
        file,
        fileList
      }) {},
      handleOk() {
        this.$http.post('/export/storage_buy', {
          ...this.form
        }).then(res => {
          const tempwindow = window.open()
          tempwindow.location = process.env.VUE_APP_BASE_URL + `${res.data.url}`
        }).finally(() => {})
      },
      handleCancel() {
        this.$emit('hide')
      }
    }
  }
</script>
<style lang="scss" scoped>
  .tips {
    color: gray;
    font-size: 80%;
  }
</style>
